
const request = require('../../../utils/request');
var page = 1,limit = 10;

function loadingData(that,page,limit){
    if(that.data.upflag){
        var url = '';
        if(that.data.name == 'discount'){
            url = 'preferential'
        }else{
            url = 'recommend'
        }
        console.log(that.data.name)
        request.HttpRequst(true,url,false,'',{"page":page,"limit":limit},"GET",false,res => {
            console.log(res.data)
            if(res.data.data != ''){
                let goodsData = that.data.goods.concat(res.data.data)
                that.setData({
                    goods: goodsData
                })
            }else{
                that.setData({
                    upflag: false
                })
            }
        })
    }
    
}


Page({
    data: {
        goods: [],
        name: '',
        upflag: true,
        imgUrl:request.imgUrl
    },
    onLoad(e) {
        console.log(request.imgUrl)
        var name = e.name;
        let page = 1;
        if(name == 'discount'){
            request.HttpRequst(true,'preferential',false,'',{"page":page,"limit":limit},"GET",false,res => {
                console.log(res.data);
                this.setData({
                    goods: res.data.data
                })
            })
            wx.setNavigationBarTitle({
                title: '特惠专区'
            })
        }else{
            request.HttpRequst(true,'recommend',false,'',{"page":page,"limit":limit},"GET",false,res => {
                console.log(res.data);
                this.setData({
                    goods: res.data.data
                })
            })
            wx.setNavigationBarTitle({
                title: '为你推荐'
            })
        }
        this.setData({
            name: e.name
        })
        
    },
    /*下拉获取更多电影数据*/
    onReachBottom:function(){
        var that = this;
        page++;
        loadingData(that,page,limit);
    },

    urlShop(e) {
        console.log(e);
        wx.navigateTo({
            url: '../shop/shop?id='+e.currentTarget.dataset.id
        })
    }
})